﻿/**  版本信息模板在安装目录下，可自行修改。
* LTR_CJO.cs
*
* 功 能： N/A
* 类 名： LTR_CJO
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2014/10/14 6:22:25   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DataLib.DBUtility;//Please add references
namespace DataLib.DAL
{
	/// <summary>
	/// 数据访问类:LTR_CJO
	/// </summary>
	public partial class LTR_CJO
	{
		public LTR_CJO()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("id", "LTR_CJO"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int? id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from LTR_CJO");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(DataLib.Model.LTR_CJO model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into LTR_CJO(");
            strSql.Append("loadnumid,loadnum,cjoid,cjono,loadcreatedate,cjocreatedate,cjotype,cjocreatecity,cjocollcity,cjoshowmanno,cjoshowmanname,customerid,customercode,customername,customershortname,projectid,projectcode,projectname,projectcity,reservecolldate,collmonth,goodsinfo,bussinesstype,rubbishtype,nwt,wrldate,tallydate,cjostatus,CEDate,CADate,CJOMemo,wrlid,billsconfirmid,directsellid,tallyid,cleartype)");
			strSql.Append(" values (");
            strSql.Append("@loadnumid,@loadnum,@cjoid,@cjono,@loadcreatedate,@cjocreatedate,@cjotype,@cjocreatecity,@cjocollcity,@cjoshowmanno,@cjoshowmanname,@customerid,@customercode,@customername,@customershortname,@projectid,@projectcode,@projectname,@projectcity,@reservecolldate,@collmonth,@goodsinfo,@bussinesstype,@rubbishtype,@nwt,@wrldate,@tallydate,@cjostatus,@CEDate,@CADate,@CJOMemo,@wrlid,@billsconfirmid,@directsellid,@tallyid,@cleartype)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@loadnumid", SqlDbType.Int,4),
					new SqlParameter("@loadnum", SqlDbType.VarChar,20),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@cjono", SqlDbType.VarChar,30),
					new SqlParameter("@loadcreatedate", SqlDbType.VarChar,20),
					new SqlParameter("@cjocreatedate", SqlDbType.VarChar,20),
					new SqlParameter("@cjotype", SqlDbType.VarChar,20),
					new SqlParameter("@cjocreatecity", SqlDbType.VarChar,20),
					new SqlParameter("@cjocollcity", SqlDbType.VarChar,20),
					new SqlParameter("@cjoshowmanno", SqlDbType.VarChar,20),
					new SqlParameter("@cjoshowmanname", SqlDbType.VarChar,200),
					new SqlParameter("@customerid", SqlDbType.Int,4),
					new SqlParameter("@customercode", SqlDbType.VarChar,50),
					new SqlParameter("@customername", SqlDbType.VarChar,200),
					new SqlParameter("@customershortname", SqlDbType.VarChar,50),
					new SqlParameter("@projectid", SqlDbType.Int,4),
					new SqlParameter("@projectcode", SqlDbType.VarChar,100),
					new SqlParameter("@projectname", SqlDbType.VarChar,200),
					new SqlParameter("@projectcity", SqlDbType.VarChar,20),
					new SqlParameter("@reservecolldate", SqlDbType.VarChar,20),
					new SqlParameter("@collmonth", SqlDbType.VarChar,8),
					new SqlParameter("@goodsinfo", SqlDbType.VarChar,1000),
					new SqlParameter("@bussinesstype", SqlDbType.VarChar,20),
					new SqlParameter("@rubbishtype", SqlDbType.VarChar,200),
					new SqlParameter("@nwt", SqlDbType.Decimal,9),
					new SqlParameter("@wrldate", SqlDbType.VarChar,20),
					new SqlParameter("@tallydate", SqlDbType.VarChar,20),
					new SqlParameter("@cjostatus", SqlDbType.VarChar,20),
					new SqlParameter("@CEDate", SqlDbType.VarChar,20),
					new SqlParameter("@CADate", SqlDbType.VarChar,20),
					new SqlParameter("@CJOMemo", SqlDbType.VarChar,300),
					new SqlParameter("@wrlid", SqlDbType.Int,4),
					new SqlParameter("@billsconfirmid", SqlDbType.Int,4),
					new SqlParameter("@directsellid", SqlDbType.Int,4),
					new SqlParameter("@tallyid", SqlDbType.Int,4),
                    new SqlParameter("@cleartype",SqlDbType.VarChar,30)};
			parameters[0].Value = model.loadnumid;
			parameters[1].Value = model.loadnum;
			parameters[2].Value = model.cjoid;
			parameters[3].Value = model.cjono;
			parameters[4].Value = model.loadcreatedate;
			parameters[5].Value = model.cjocreatedate;
			parameters[6].Value = model.cjotype;
			parameters[7].Value = model.cjocreatecity;
			parameters[8].Value = model.cjocollcity;
			parameters[9].Value = model.cjoshowmanno;
			parameters[10].Value = model.cjoshowmanname;
			parameters[11].Value = model.customerid;
			parameters[12].Value = model.customercode;
			parameters[13].Value = model.customername;
			parameters[14].Value = model.customershortname;
			parameters[15].Value = model.projectid;
			parameters[16].Value = model.projectcode;
			parameters[17].Value = model.projectname;
			parameters[18].Value = model.projectcity;
			parameters[19].Value = model.reservecolldate;
			parameters[20].Value = model.collmonth;
			parameters[21].Value = model.goodsinfo;
			parameters[22].Value = model.bussinesstype;
			parameters[23].Value = model.rubbishtype;
			parameters[24].Value = model.nwt;
			parameters[25].Value = model.wrldate;
			parameters[26].Value = model.tallydate;
			parameters[27].Value = model.cjostatus;
			parameters[28].Value = model.CEDate;
			parameters[29].Value = model.CADate;
			parameters[30].Value = model.CJOMemo;
			parameters[31].Value = model.wrlid;
			parameters[32].Value = model.billsconfirmid;
			parameters[33].Value = model.directsellid;
			parameters[34].Value = model.tallyid;
            parameters[35].Value = model.cleartype;
			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DataLib.Model.LTR_CJO model)
		{
			StringBuilder strSql=new StringBuilder();
            if(model.wrldate!=null && model.wrldate !="" && (model.cjostatus=="待称重" || model.cjostatus=="派车中"))
            {
                model.cjostatus = "处理中";
            }
            strSql.Clear();
			strSql.Append("update LTR_CJO set ");
			strSql.Append("loadnumid=@loadnumid,");
			strSql.Append("loadnum=@loadnum,");
			strSql.Append("cjoid=@cjoid,");
			strSql.Append("cjono=@cjono,");
			strSql.Append("loadcreatedate=@loadcreatedate,");
			strSql.Append("cjocreatedate=@cjocreatedate,");
			strSql.Append("cjotype=@cjotype,");
			strSql.Append("cjocreatecity=@cjocreatecity,");
			strSql.Append("cjocollcity=@cjocollcity,");
			strSql.Append("cjoshowmanno=@cjoshowmanno,");
			strSql.Append("cjoshowmanname=@cjoshowmanname,");
			strSql.Append("customerid=@customerid,");
			strSql.Append("customercode=@customercode,");
			strSql.Append("customername=@customername,");
			strSql.Append("customershortname=@customershortname,");
			strSql.Append("projectid=@projectid,");
			strSql.Append("projectcode=@projectcode,");
			strSql.Append("projectname=@projectname,");
			strSql.Append("projectcity=@projectcity,");
			strSql.Append("reservecolldate=@reservecolldate,");
			strSql.Append("collmonth=@collmonth,");
			strSql.Append("goodsinfo=@goodsinfo,");
			strSql.Append("bussinesstype=@bussinesstype,");
			strSql.Append("rubbishtype=@rubbishtype,");
			strSql.Append("nwt=@nwt,");
			strSql.Append("wrldate=@wrldate,");
			strSql.Append("tallydate=@tallydate,");
			strSql.Append("cjostatus=@cjostatus,");
			strSql.Append("CEDate=@CEDate,");
			strSql.Append("CADate=@CADate,");
			strSql.Append("CJOMemo=@CJOMemo,");
			strSql.Append("wrlid=@wrlid,");
			strSql.Append("billsconfirmid=@billsconfirmid,");
			strSql.Append("directsellid=@directsellid,");
			strSql.Append("tallyid=@tallyid,");
            strSql.Append("cleartype=@cleartype");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@loadnumid", SqlDbType.Int,4),
					new SqlParameter("@loadnum", SqlDbType.VarChar,20),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@cjono", SqlDbType.VarChar,30),
					new SqlParameter("@loadcreatedate", SqlDbType.VarChar,20),
					new SqlParameter("@cjocreatedate", SqlDbType.VarChar,20),
					new SqlParameter("@cjotype", SqlDbType.VarChar,20),
					new SqlParameter("@cjocreatecity", SqlDbType.VarChar,20),
					new SqlParameter("@cjocollcity", SqlDbType.VarChar,20),
					new SqlParameter("@cjoshowmanno", SqlDbType.VarChar,20),
					new SqlParameter("@cjoshowmanname", SqlDbType.VarChar,200),
					new SqlParameter("@customerid", SqlDbType.Int,4),
					new SqlParameter("@customercode", SqlDbType.VarChar,50),
					new SqlParameter("@customername", SqlDbType.VarChar,200),
					new SqlParameter("@customershortname", SqlDbType.VarChar,50),
					new SqlParameter("@projectid", SqlDbType.Int,4),
					new SqlParameter("@projectcode", SqlDbType.VarChar,100),
					new SqlParameter("@projectname", SqlDbType.VarChar,200),
					new SqlParameter("@projectcity", SqlDbType.VarChar,20),
					new SqlParameter("@reservecolldate", SqlDbType.VarChar,20),
					new SqlParameter("@collmonth", SqlDbType.VarChar,8),
					new SqlParameter("@goodsinfo", SqlDbType.VarChar,1000),
					new SqlParameter("@bussinesstype", SqlDbType.VarChar,20),
					new SqlParameter("@rubbishtype", SqlDbType.VarChar,200),
					new SqlParameter("@nwt", SqlDbType.Decimal,9),
					new SqlParameter("@wrldate", SqlDbType.VarChar,20),
					new SqlParameter("@tallydate", SqlDbType.VarChar,20),
					new SqlParameter("@cjostatus", SqlDbType.VarChar,20),
					new SqlParameter("@CEDate", SqlDbType.VarChar,20),
					new SqlParameter("@CADate", SqlDbType.VarChar,20),
					new SqlParameter("@CJOMemo", SqlDbType.VarChar,300),
					new SqlParameter("@wrlid", SqlDbType.Int,4),
					new SqlParameter("@billsconfirmid", SqlDbType.Int,4),
					new SqlParameter("@directsellid", SqlDbType.Int,4),
					new SqlParameter("@tallyid", SqlDbType.Int,4),
					new SqlParameter("@id", SqlDbType.Int,4),
                    new SqlParameter("@cleartype",SqlDbType.VarChar,30)};
			parameters[0].Value = model.loadnumid;
			parameters[1].Value = model.loadnum;
			parameters[2].Value = model.cjoid;
			parameters[3].Value = model.cjono;
			parameters[4].Value = model.loadcreatedate;
			parameters[5].Value = model.cjocreatedate;
			parameters[6].Value = model.cjotype;
			parameters[7].Value = model.cjocreatecity;
			parameters[8].Value = model.cjocollcity;
			parameters[9].Value = model.cjoshowmanno;
			parameters[10].Value = model.cjoshowmanname;
			parameters[11].Value = model.customerid;
			parameters[12].Value = model.customercode;
			parameters[13].Value = model.customername;
			parameters[14].Value = model.customershortname;
			parameters[15].Value = model.projectid;
			parameters[16].Value = model.projectcode;
			parameters[17].Value = model.projectname;
			parameters[18].Value = model.projectcity;
			parameters[19].Value = model.reservecolldate;
			parameters[20].Value = model.collmonth;
			parameters[21].Value = model.goodsinfo;
			parameters[22].Value = model.bussinesstype;
			parameters[23].Value = model.rubbishtype;
			parameters[24].Value = model.nwt;
			parameters[25].Value = model.wrldate;
			parameters[26].Value = model.tallydate;
			parameters[27].Value = model.cjostatus;
			parameters[28].Value = model.CEDate;
			parameters[29].Value = model.CADate;
			parameters[30].Value = model.CJOMemo;
			parameters[31].Value = model.wrlid;
			parameters[32].Value = model.billsconfirmid;
			parameters[33].Value = model.directsellid;
			parameters[34].Value = model.tallyid;
			parameters[35].Value = model.id;
            parameters[36].Value = model.cleartype;
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int? id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from LTR_CJO ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from LTR_CJO ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.LTR_CJO GetModel(int? id)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 id,loadnumid,loadnum,cjoid,cjono,loadcreatedate,cjocreatedate,cjotype,cjocreatecity,cjocollcity,cjoshowmanno,cjoshowmanname,customerid,customercode,customername,customershortname,projectid,projectcode,projectname,projectcity,reservecolldate,collmonth,goodsinfo,bussinesstype,rubbishtype,nwt,wrldate,tallydate,cjostatus,CEDate,CADate,CJOMemo,wrlid,billsconfirmid,directsellid,tallyid,cleartype from LTR_CJO ");
			strSql.Append(" where id=@id");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
			};
			parameters[0].Value = id;

			DataLib.Model.LTR_CJO model=new DataLib.Model.LTR_CJO();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.LTR_CJO DataRowToModel(DataRow row)
		{
			DataLib.Model.LTR_CJO model=new DataLib.Model.LTR_CJO();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["loadnumid"]!=null && row["loadnumid"].ToString()!="")
				{
					model.loadnumid=int.Parse(row["loadnumid"].ToString());
				}
				if(row["loadnum"]!=null)
				{
					model.loadnum=row["loadnum"].ToString();
				}
				if(row["cjoid"]!=null && row["cjoid"].ToString()!="")
				{
					model.cjoid=int.Parse(row["cjoid"].ToString());
				}
				if(row["cjono"]!=null)
				{
					model.cjono=row["cjono"].ToString();
				}
				if(row["loadcreatedate"]!=null)
				{
					model.loadcreatedate=row["loadcreatedate"].ToString();
				}
				if(row["cjocreatedate"]!=null)
				{
					model.cjocreatedate=row["cjocreatedate"].ToString();
				}
				if(row["cjotype"]!=null)
				{
					model.cjotype=row["cjotype"].ToString();
				}
				if(row["cjocreatecity"]!=null)
				{
					model.cjocreatecity=row["cjocreatecity"].ToString();
				}
				if(row["cjocollcity"]!=null)
				{
					model.cjocollcity=row["cjocollcity"].ToString();
				}
				if(row["cjoshowmanno"]!=null)
				{
					model.cjoshowmanno=row["cjoshowmanno"].ToString();
				}
				if(row["cjoshowmanname"]!=null)
				{
					model.cjoshowmanname=row["cjoshowmanname"].ToString();
				}
				if(row["customerid"]!=null && row["customerid"].ToString()!="")
				{
					model.customerid=int.Parse(row["customerid"].ToString());
				}
				if(row["customercode"]!=null)
				{
					model.customercode=row["customercode"].ToString();
				}
				if(row["customername"]!=null)
				{
					model.customername=row["customername"].ToString();
				}
				if(row["customershortname"]!=null)
				{
					model.customershortname=row["customershortname"].ToString();
				}
				if(row["projectid"]!=null && row["projectid"].ToString()!="")
				{
					model.projectid=int.Parse(row["projectid"].ToString());
				}
				if(row["projectcode"]!=null)
				{
					model.projectcode=row["projectcode"].ToString();
				}
				if(row["projectname"]!=null)
				{
					model.projectname=row["projectname"].ToString();
				}
				if(row["projectcity"]!=null)
				{
					model.projectcity=row["projectcity"].ToString();
				}
				if(row["reservecolldate"]!=null)
				{
					model.reservecolldate=row["reservecolldate"].ToString();
				}
				if(row["collmonth"]!=null)
				{
					model.collmonth=row["collmonth"].ToString();
				}
				if(row["goodsinfo"]!=null)
				{
					model.goodsinfo=row["goodsinfo"].ToString();
				}
				if(row["bussinesstype"]!=null)
				{
					model.bussinesstype=row["bussinesstype"].ToString();
				}
				if(row["rubbishtype"]!=null)
				{
					model.rubbishtype=row["rubbishtype"].ToString();
				}
				if(row["nwt"]!=null && row["nwt"].ToString()!="")
				{
					model.nwt=decimal.Parse(row["nwt"].ToString());
				}
				if(row["wrldate"]!=null)
				{
					model.wrldate=row["wrldate"].ToString();
				}
				if(row["tallydate"]!=null)
				{
					model.tallydate=row["tallydate"].ToString();
				}
				if(row["cjostatus"]!=null)
				{
					model.cjostatus=row["cjostatus"].ToString();
				}
				if(row["CEDate"]!=null)
				{
					model.CEDate=row["CEDate"].ToString();
				}
				if(row["CADate"]!=null)
				{
					model.CADate=row["CADate"].ToString();
				}
				if(row["CJOMemo"]!=null)
				{
					model.CJOMemo=row["CJOMemo"].ToString();
				}
				if(row["wrlid"]!=null && row["wrlid"].ToString()!="")
				{
					model.wrlid=int.Parse(row["wrlid"].ToString());
				}
				if(row["billsconfirmid"]!=null && row["billsconfirmid"].ToString()!="")
				{
					model.billsconfirmid=int.Parse(row["billsconfirmid"].ToString());
				}
				if(row["directsellid"]!=null && row["directsellid"].ToString()!="")
				{
					model.directsellid=int.Parse(row["directsellid"].ToString());
				}
				if(row["tallyid"]!=null && row["tallyid"].ToString()!="")
				{
					model.tallyid=int.Parse(row["tallyid"].ToString());
				}
                if (row["cleartype"] != null && row["cleartype"].ToString() == "")
                {
                    model.cleartype = row["cleartype"].ToString();
                }
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select id,loadnumid,loadnum,cjoid,cjono,loadcreatedate,cjocreatedate,cjotype,cjocreatecity,cjocollcity,cjoshowmanno,cjoshowmanname,customerid,customercode,customername,customershortname,projectid,projectcode,projectname,projectcity,reservecolldate,collmonth,goodsinfo,bussinesstype,rubbishtype,nwt,wrldate,tallydate,cjostatus,CEDate,CADate,CJOMemo,wrlid,billsconfirmid,directsellid,tallyid,cleartype ");
			strSql.Append(" FROM LTR_CJO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
            strSql.Append(" id,loadnumid,loadnum,cjoid,cjono,loadcreatedate,cjocreatedate,cjotype,cjocreatecity,cjocollcity,cjoshowmanno,cjoshowmanname,customerid,customercode,customername,customershortname,projectid,projectcode,projectname,projectcity,reservecolldate,collmonth,goodsinfo,bussinesstype,rubbishtype,nwt,wrldate,tallydate,cjostatus,CEDate,CADate,CJOMemo,wrlid,billsconfirmid,directsellid,tallyid,cleartype ");
			strSql.Append(" FROM LTR_CJO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM LTR_CJO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from LTR_CJO T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "LTR_CJO";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

        public Model.LTR_CJO GetModelByCjoID(int cjoid)
        {
            Model.LTR_CJO model = new Model.LTR_CJO();
            DataTable dt = GetList("cjoid=" + cjoid.ToString()).Tables[0];
            if (dt != null && dt.Rows.Count > 0) {
                model = DataRowToModel(dt.Rows[0]);
            }

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListFormat(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,loadnumid,loadnum,loadcreatedate,cjoid,cjono,cjocreatedate,cjotype,cjocreatecity,cjocollcity,cjoshowmanno,cjoshowmanname,customerid,customercode,customername,customershortname,projectid,projectcode,projectname,projectcity,reservecolldate,collmonth,goodsinfo,bussinesstype,rubbishtype,nwt,cjostatus,CEDate,CADate,CJOMemo,wrlid,billsconfirmid,directsellid,tallyid,cleartype ");
            strSql.Append(",case wrldate when NULL then '' ");
            strSql.Append("when '' then '' ");
            strSql.Append("else (Cast(YEAR(wrldate) as varchar(4))+ '-' ");
            strSql.Append("+right('00'+Cast(MONTH(wrldate) as varchar(2)),2)+'-' ");
            strSql.Append("+right('00'+Cast(DAY(wrldate) as varchar(2)),2)) END wrldate");
            strSql.Append(",case tallydate when NULL then '' ");
            strSql.Append("when '' then '' ");
            strSql.Append("else (Cast(YEAR(tallydate) as varchar(4))+ '-' ");
            strSql.Append("+right('00'+Cast(MONTH(tallydate) as varchar(2)),2)+'-' ");
            strSql.Append("+right('00'+Cast(DAY(tallydate) as varchar(2)),2)) END tallydate ");
            strSql.Append(" FROM LTR_CJO ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" Order by loadnum,cjono");
            return DbHelperSQL.Query(strSql.ToString());
        }

		#endregion  ExtensionMethod
	}
}

